import 'package:flutter/material.dart';

class ConstraintDemo extends StatelessWidget {
  final Widget redBox=DecoratedBox(
    decoration: BoxDecoration(color: Colors.red),
  );

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: Text('限制类容器例子'),
        actions: <Widget>[
          UnconstrainedBox(
            child: Padding(
              padding: EdgeInsets.only(right: 20),
              child: SizedBox(
                width: 20,
                height: 20,
                child: CircularProgressIndicator(
                  strokeWidth: 3,
                  valueColor: AlwaysStoppedAnimation(Colors.white70),
                ),
              ),
            ),
          ),
        ],
      ),
      body: Column(
        children: <Widget>[
          Padding(
            padding: EdgeInsets.only(top:10),
            child: ConstrainedBox(
              constraints: BoxConstraints(
                minHeight: 50,  // 最小高度为50像素
                minWidth: double.infinity,  // 宽度尽可能大
              ),
              child: Container(
                height: 5, // 由于ConstrainedBox的限制minHeight: 50, 这个高度5无效
                child: redBox,
              ),
            ),
          ),

          Padding(
            padding: EdgeInsets.only(top:10),
            child: SizedBox(
              width: 80,
              height: 80,
              child: redBox,
            ),
          ),

          Padding(
            padding: EdgeInsets.only(top:10),
            child: ConstrainedBox(
              constraints: BoxConstraints(
                minHeight: 60,
                minWidth: 60,
              ),
              child: ConstrainedBox(
                constraints: BoxConstraints(
                  minWidth: 90,
                  minHeight: 20
                ),
                child: redBox,
              ),
            ),
          ),

          Padding(
            padding: EdgeInsets.only(top:10),
            child: ConstrainedBox(
              constraints: BoxConstraints(
                minHeight: 20,
                minWidth: 90,
              ),
              child: ConstrainedBox(
                constraints: BoxConstraints(
                    minWidth: 60,
                    minHeight: 60
                ),
                child: redBox,
              ),
            ),
          ),

        ],
      ),
    );
  }
}